package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cyy.ultra_ptr_demo.R;

import java.util.List;

/**
 * Created by 999555yun on 2016/9/24.
 */
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    //初始化适配器
    private LayoutInflater mLayoutInflater;
    private Context mContext;
    private List<String> mTitle;
    public RecyclerAdapter(Context context,List<String> title){
        mContext=context;
        mTitle=title;
        mLayoutInflater=LayoutInflater.from(context);
    }

    //首先是自定义的ViewHolder。持有每个Item界面的元素
    public static class NormalViewHolder extends RecyclerView.ViewHolder{
        TextView textView ;
        public NormalViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.recr_textview);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new NormalViewHolder(mLayoutInflater.inflate(R.layout.rv_item,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        NormalViewHolder viewHolder = (NormalViewHolder) holder;
        viewHolder.textView.setText(mTitle.get(position));
    }

    @Override
    public int getItemCount() {
        return mTitle ==null ? 0 : mTitle.size();
    }
}
